package acwing._2LanQiao._7Greedy;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._2LanQiao._7Greedy
 * @File : Q0104.java
 * @Author : WangRuoyu
 * @Date : 2023/3/20 9:44
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Q0104 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] words = br.readLine().split(" ");

        int n = Integer.parseInt(words[0]);
        int[] d = new int[n];

        words = br.readLine().split(" ");
        for (int i = 0; i < n; ++i) {
            d[i] = Integer.parseInt(words[i]);
        }

        Arrays.sort(d);

        System.out.println(Arrays.toString(d));

        int mid = d[(n - 1) >> 1];

        int res = 0;
        for (int i = 0; i < n; ++i) {
            res += Math.abs(d[i] - mid);
        }

        System.out.println(res);
    }
}

